package com.ncloud.billing;

import java.text.ParseException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import com.alibaba.fastjson.JSONObject;
import com.ncloud.billing.service.GenBillService;
import com.ncloud.billing.service.GenChnlBillService;

@SpringBootApplication
@ComponentScan(basePackages="main.com.ncloud,com.ncloud")
public class SpringBillingApplication {
	public static void main(String[] args) throws ParseException {
		ConfigurableApplicationContext ct=SpringApplication.run(SpringBillingApplication.class, args);
		boolean genCustBill=false;
		boolean genChnlBill=false;
		if(args.length==0){
			genCustBill=true;
			genChnlBill=true;
		}else if(args.length==1){
			if("0".equals(args[0])){
				genCustBill=true;
				genChnlBill=true;
			}else if("1".equals(args[0])){
				genCustBill=true;
			}else if("2".equals(args[0])){
				genChnlBill=true;
			}
		}
		//AccountConfig accountConfig = (AccountConfig)ct.getBean(AccountConfig.class);
		JSONObject json=new JSONObject();
		//json.put("bill_cycle_id", accountConfig.getBillCycleId());
		//json.put("cust_ids", accountConfig.getCustIds());
		if(genCustBill){
			GenBillService genBillService = (GenBillService)ct.getBean(GenBillService.class);
			genBillService.genCustBill(json);
		}
		if(genChnlBill){
			GenChnlBillService genChnlBillService = (GenChnlBillService)ct.getBean(GenChnlBillService.class);
			genChnlBillService.genChnlBill(json);
		}
		SpringApplication.exit(ct);
		//================================================
		/*Calendar c = Calendar.getInstance();
		c.set(Calendar.YEAR,201702/100);
		c.set(Calendar.MONTH,201702%100);
		Integer currentMonthDays=c.getActualMaximum(Calendar.DAY_OF_MONTH);
		
		SimpleDateFormat systemdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
		//出账月月初时间和月末时间
		Date billDeginDate=systemdf.parse("2017-02-01 23:59:59");
		Date billEndDate=systemdf.parse("2017-02-27 23:59:59");
		Date nodeBeginDate = billDeginDate;
		Date nodeEndDate = billEndDate;
		Date nowDate=systemdf.parse("2017-02-14 00:00:00");
		Integer useDays=currentMonthDays;//默认是账期一个月的天数
		useDays=DateUtil.daysBetween(nodeBeginDate, nodeEndDate);
		useDays=DateUtil.daysBetween(nodeBeginDate, nowDate);
		useDays=DateUtil.daysBetween(nowDate,nodeEndDate);
		SpringApplication.exit(ct);*/
		//================================================
	}
}
